<?php

namespace App\Http\Resources\Train\Trip;

use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use JsonSerializable;

class InviteResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param Request $request
     *
     * @return array|Arrayable|JsonSerializable
     */
    public function toArray($request)
    {
        $invite_info = parent::toArray($request);
        if (isset($invite_info['joins'])) {
            $invite_info['joins'] = InviteJoinsResource::collection($invite_info['joins']);
        }
        unset($invite_info['user_id'],
            $invite_info['train_code'],
            $invite_info['from_station_code'],
            $invite_info['to_station_code'],
            $invite_info['train_date'],
            $invite_info['created_at'],
            $invite_info['updated_at']
        );
        return $invite_info;
    }
}
